package extensions

import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody
import okio.BufferedSink
import okio.source
import java.io.IOException
import java.io.InputStream

fun InputStream.asRequestBody() = object : RequestBody(){
    override fun contentType(): MediaType? = "multipart/form-data".toMediaType()

    override fun writeTo(sink: BufferedSink) {
        try {
            val source = source()
            sink.writeAll(source)
            source.close()
        }catch (ex : IOException)
        {
            ex.printStackTrace()
        }
    }

}

